﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace BDSim
{
    public struct Ephemeris_16
    {
        public UTCTime t;				//toe对应的UTC时间
        public int WN;             //参考时刻周（待计算的导航时间系统）
        public double toe;            //参考时刻周内秒(s)（待计算的导航时间系统）
        public double sqrtA;			//半长轴的平方根(m^(1/2))
        public double e;				//偏心率(无单位)
        public double i;  			//参考时刻的轨道倾角(rad)
        public double Omega0;			//按参考时刻计算的升交点赤经(rad)
        public double w;				//近地点幅角(rad)
        public double M;				//参考时刻的平近点角(rad)
        public double deltaN;			//卫星平均运动速率与计算值之差(rad/s)
        public double OmegaDot;       //升交点赤经变化率(rad/s)
        public double idot;           //轨道倾角变化率(rad/s)
        public double Cus;			//(rad)
        public double Cuc;			//纬度幅角的余弦调和改正项的振幅(rad)
        public double Crs;			//(m)
        public double Crc;			//(m)	
        public double Cis;			//(rad)
        public double Cic;			//(rad)

        /// <summary>
        /// 从导航电文加载星历数据
        /// </summary>
        /// <param name="NavMsg"></param>
        public void LoadDataFromRinexNavMsg(RinexFileDataType.NavMessage_Rinex NavMsg)
        {
            this.Cic = NavMsg.Cic_3;
            this.Cis = NavMsg.Cis_3;
            this.Crc = NavMsg.Crc_4;
            this.Crs = NavMsg.Crs_1;
            this.Cuc = NavMsg.Cuc_2;
            this.Cus = NavMsg.Cus_2;
            this.deltaN = NavMsg.dn_1;
            this.e = NavMsg.e_2;
            this.i = NavMsg.i0_4;
            this.idot = NavMsg.IDOT_5;
            this.M = NavMsg.M0_1;
            this.Omega0 = NavMsg.omega_3;
            this.OmegaDot = NavMsg.OMEGADOT_4;
            this.sqrtA = NavMsg.sqtA_2;
            this.w = NavMsg.w_4;
            this.toe = NavMsg.TOE_3;
            this.WN = (int)NavMsg.Wk_5;
            this.t.Year = NavMsg.Epoch.year;//将两位的年转化为四位的年
            if (this.t.Year < 2000)
            {
                if (this.t.Year > 80)//以80年作为临界标准暂时安全
                {
                    this.t.Year += 1900;
                }
                else
                {
                    this.t.Year += 2000;
                }
            }
            this.t.Mon = NavMsg.Epoch.Mon;
            this.t.Day = NavMsg.Epoch.day;
            this.t.Hour = NavMsg.Epoch.hour;
            this.t.Min = NavMsg.Epoch.Min;
            this.t.Sec = NavMsg.Epoch.Sec;
            TimeSpaceDll.CAL2UTC(out this.t, 1);
        }
    };

    /* 星历误差参数 （Add by lhz2016.7.8）*/
    public struct EphErrParam
    {
        public double AmpR;   //R方向正弦误差幅值（单位：米）
        public double AmpT;   //T方向正弦误差幅值（单位：米）
        public double AmpN;   //N方向正弦误差幅值（单位：米）
        public double T;      //正弦误差信号周期 （单位：秒）
        public double H_leve; //白噪声误差量级（单位：米）
    };
     
    public struct NavEphFit_Input
    {
        public EConstellationType NavSysType;
        public UTCTime SysStartTime;
        public UTCTime FitTime;
        public int SatType;
        public double LeapSec;
    };

    public struct NavEphFit_ControlParam
    {
        public int IsAddErr;
        public int SunPert;//太阳摄动开关
        public int MoonPert;//月球摄动开关
        public EphErrParam ErrParam;
    };

    public struct GlonassEph
    {
       public UTCTime t;
       public double x;
       public double y;
       public double z;
       public double vx;
       public double vy;
       public double vz;
       public double ax;
       public double ay;
       public double az;
    };

    public struct NavEphFit_Output
    {
        public GlonassEph GloEph;
        public Ephemeris_16 SixEph;
    };    
}
